'''
Created on Dec 4, 2010

@author: Nican
'''

import wx.lib.plot as plot

class Graph(plot.PlotCanvas):
    '''
    classdocs
    '''


    def __init__(self, parent):
        '''
        Constructor
        '''
        plot.PlotCanvas.__init__(self, parent)
        
        
        
    def GraphUpdate(self, points):
        if len(points) == 0:
            return
        
        NumPoints = 1000
        startTime = self.GetParent().StartTime
        
        # list of (x,y) data point tuples
        dataYaw = []
        dataPitch = []
        dataRow = []
        ControllerZ = []
        dataEStop = []
        
        yAxis = (0, 360)
        xAxis = (points[max(-NumPoints, -len(points))].creationTime-startTime,
               points[-1].creationTime-startTime)
        
        for point in points[-NumPoints:]:
            dataYaw.append((point.creationTime-startTime, point.Imu.y))
            dataPitch.append((point.creationTime-startTime, point.Imu.p))
            dataRow.append((point.creationTime-startTime, point.Imu.r))
            ControllerZ.append((point.creationTime-startTime, point.returnData.zVal * 360))
            dataEStop.append((point.creationTime-startTime, point.eStop * 120))

        # draw points as a line
        line = plot.PolyLine(dataPitch, colour='red', width=1)
        line2 = plot.PolyLine(dataYaw, colour='green', width=1)
        line3 = plot.PolyLine(dataRow, colour='blue', width=1)
        line4 = plot.PolyLine(ControllerZ, colour='black', width=1)
        line5 = plot.PolyLine(dataEStop, colour='purple', width=1)
        # also draw markers, default colour is black and size is 2
        # other shapes 'circle', 'cross', 'square', 'dot', 'plus'
        #marker = plot.PolyMarker(data, marker='dot')
        # set up text, axis and draw
        gc = plot.PlotGraphics([line, line2, line3, line4, line5], 'Octorotor Attitude', 'Time (seconds)', 'Angle (degrees)')
        self.Draw(gc, yAxis=yAxis, xAxis=xAxis)
        
